﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace VSM
{
    public partial class Homepage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session[Utils.AppConstants.ID_User] == null || Session[Utils.AppConstants.Password] == null || Session[Utils.AppConstants.ID_Dealer] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                else if(!IsPostBack)
                {
                    if (Session[VSM.Utils.AppConstants.U_Department].ToString() == VSM.Utils.AppConstants.SALES)
                    {
                        if (Session[VSM.Utils.AppConstants.ID_Dealer].ToString() == VSM.Utils.AppConstants.VSM)
                        {
                            UCSOPending.Visible = 
                            UCVehicleServicePending.Visible = true;
                            UCVSMSOPending.Visible = 
                            UCPOPending.Visible = false;
                        }
                        else // Dealer
                        {
                            UCSOPending.Visible = 
                            UCVehicleServicePending.Visible = false;
                            UCVSMSOPending.Visible = 
                            UCPOPending.Visible = true;
                        }
                    }
                }
                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                //            "javascript:Main.openDialog(\"../Popup_EditItem.aspx\",id=\"" + "1" + "\")", true);

                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ShowLoader", "Dialog.showLoader();", true);

                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                //        "Main.setMasterMessage('Connecting to SAP.....','');", true);

                //GetDefault df = new GetDefault();
                //df.GetConnection(HttpContext.Current.User.Identity.Name);

                //if (df.GetConnection(HttpContext.Current.User.Identity.Name) == -1)
                //{
                //    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                //        "Main.setMasterMessage('Connect to SAP Failed!','');", true);
                //}
                ////else
                ////{
                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "OKErrors",
                //        "Main.setMasterMessage('Creating UDFs.....','');", true);

                //df.CreateUDF(HttpContext.Current.User.Identity.Name);
                //}

                //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading",
                //                                        "Dialog.hideLoader();", true);

              
            }
            catch(Exception)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "CloseLoading",
                                                        "Dialog.hideLoader();", true);
            }
           
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            //string popup = "showNofify('asdada')";
            //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CallJS", popup, true);
            Timer1.Enabled = false;
        }

        protected override void OnLoadComplete(EventArgs e)
        {
            base.OnLoadComplete(e);
            if (this.Request["__EVENTARGUMENT"] != null && this.Request["__EVENTARGUMENT"].ToString() != "")
            {
                string dbType = Session[Utils.AppConstants.ID_Dealer].ToString() == "VSM" ? Utils.AppConstants.VSM : Utils.AppConstants.DEALER;
                switch (this.Request["__EVENTARGUMENT"].ToString())
                {
                    case "UpdateVehicleServiceDate":
                        Response.Redirect("Homepage.aspx");
                        break;

                    default:
                        break;
                }
            }
        }
    }
}